//Create scope
(function () {
  var _cached=window.jQueue = function () {
    this.q=[];
	arguments[0]&&this.push(arguments[0]);
	arguments[1]&&this.start();
  } // Create object
    // new jQueue([queue],[startoncreate])
  _cached.prototype.start=function() {
    this.i&&clearInterval(this.i);
	var _cached=this;
	function step_wrapper() {
	  _cached.step.apply(_cached);
	}
	step_wrapper();
	setInterval(step_wrapper,1000);
  } // Start timing
  _cached.prototype.stop=function() {
    this.i&&clearInterval(this.i)&&this.i=null;
	this.q=[];
  } // Stop timing
  _cached.prototype.step=function () {
    
    var _ind = this.index();
	var _cur = this.q[_ind];
	if (!_cur) return;
	this.pop(_ind);
	_cur[0]&&_cur[0].apply(this,_cur[1]);
  } // Do every timer count
  _cached.prototype.push=function (a) {
    switch (typeof a) {
	  case 'function':
            this.c++;
	    this.q[this.q.length]=[a,null];
	    break;
	  case 'object':
	    if (!a.length) return;
		if (a.length>2)
		for (x in a)
		  this.push(a[x]);
		else
		  this.q[this.q.length]=[a[0],a[1]]
		
	    break;
	  case 'string':
            this.c++;
	    eval(['var _c=function(){',a,'}'].join(""))
	    this.q[this.q.length]=[_c];
	    break;
	}
  } // Push function in queue
  _cached.prototype.pop=function (i) {
	this.q[i]&&(delete this.q[i]);
    var _cached;
    (this.q[i+1])?
	(this.q[i]=this.q.pop()):
	(this.q.pop());
  } // Pop element from queue
  _cached.prototype.index=function() {
    (this.temp==null)?this.temp=0:(this.temp++)&&(this.temp%=this.q.length);
    return this.temp;
  } // Get next element
  _cached.prototype.length=function() {
    return this.q.length;
  } // Get length of queue
})();